﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Counter1
{
    /// <summary>
    /// 计算器总流程
    /// </summary>
    class Communion
    {
        //接收用户初始表达式
        public string equation = "";

        //存储检验后的表达式
        public string newequation = "";

        //存储后缀表达式
        public string postfix = "";

        //存储表达式结果
        public double result = 0.00;

        //异常处理
        public bool isnormal = true;

        public Communion (string str)
        {
            equation = str;
        }

        /// <summary>
        /// 执行表达式的一系列操作(检验、转换、求值)
        /// </summary>
        public void Carryout()
        {
            Inspect test = new Inspect(equation);
            newequation = test.Iswrong();
            if( test.errors == "")
            {
                Compositor mode = new Compositor(newequation);
                postfix = mode.Suffix();

                Calculate mode2 = new Calculate(postfix);
                mode2.Incision();
                result = mode2.Getresult();
            }
            else
            {
                isnormal = false;
                Console.WriteLine( "\n表达式: '" + equation + "' 输入有误...");
                Console.WriteLine("\n可能的原因：\n" + test.errors);
                Console.WriteLine("\n---------------------------------------------------------------------\n");
            }

        }
   
    }
}
